Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed Transforming wrapped input fields #4676

Merged
merged 5 commits into from
Aug 26, 2022
Merged

fix: Fixed Transforming wrapped input fields #4676

merged 5 commits into from
Aug 26, 2022

Conversation

NullScope
Copy link
Contributor

@NullScope NullScope commented Aug 26, 2022

🚨 IMPORTANT: Please do not create a Pull Request without creating an issue first.

Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of the pull request.

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Related #4675

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Screenshots/Sandbox (if appropriate/relevant):

Adding links to sandbox or providing screenshots can help us understand more about this PR and take action on it as appropriate

How Has This Been Tested?

Test Environment:

  • OS: macOS 12.5.1
  • @graphql-tools/wrap: 9.0.4
  • NodeJS: v16.15.0

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests and linter rules pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@changeset-bot
Copy link

changeset-bot bot commented Aug 26, 2022

🦋 Changeset detected

Latest commit: 719fc36

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@graphql-tools/wrap Patch
@graphql-tools/stitch Patch
@graphql-tools/url-loader Patch
federation-benchmark Patch
@graphql-tools/prisma-loader Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Aug 26, 2022

Someone is attempting to deploy a commit to the The Guild Team on Vercel.

A member of the Team first needs to authorize it.

@ardatan
Copy link
Owner

ardatan commented Aug 26, 2022

Thanks for the PR!
Could you add a unit test to prevent future regressions?

@@ -165,7 +167,10 @@ export default class TransformInputObjectFields<TContext = Record<string, any>>
// The casting is kind of legit here as we are in a visitor
const parentType = typeInfo.getInputType() as Maybe<GraphQLInputObjectType>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't do casting here if we have the following check right?

Copy link
Contributor Author

@NullScope NullScope Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getInputType returns a GraphQLInputType instead of GraphQLInputObjectType, and does not have the property name. So on the ternary operator if the check fails it falls back to the original logic of just parentType.name. So I am not sure how we could do this without casting it here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed with the getNamedType change

@NullScope
Copy link
Contributor Author

Thanks for the PR! Could you add a unit test to prevent future regressions?

Will do 👍

@NullScope
Copy link
Contributor Author

NullScope commented Aug 26, 2022

Unit test added, it is a copy of the first one with the exception that the argument is non-null. I decided to do it this way because while the tests are exactly the same, they test different parts of the code due to the argument differences.

If you remove the fix of this PR the unit test will fail with the following:

 FAIL  packages/wrap/tests/transformRenameInputObjectFields.test.ts
  ● RenameInputObjectFields › renaming with non-null arguments works

    expect(received).toBe(expected) // Object.is equality

    Expected: "field2"
    Received: null

      114 |     const testData: any = result.data['test'];
      115 |     expect(testData.field1).toBe('field1');
    > 116 |     expect(testData.field2).toBe('field2');
          |                             ^
      117 |   });
      118 |
      119 |   test('renaming with variables works', async () => {

      at Object.toBe (packages/wrap/tests/transformRenameInputObjectFields.test.ts:116:29)

@@ -165,7 +167,10 @@ export default class TransformInputObjectFields<TContext = Record<string, any>>
// The casting is kind of legit here as we are in a visitor
const parentType = typeInfo.getInputType() as Maybe<GraphQLInputObjectType>;
if (parentType != null) {
const parentTypeName = parentType.name;
const parentTypeName =
isWrappingType(parentType) && isInputObjectType(parentType.ofType)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related https://github.com/ardatan/graphql-tools/pull/4676/files#r956002686
Can we do getNamedType here because ofType can be also another wrapped type, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted! you can indeed have an "infinite" amount of wraps, will change it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Then could you create a changeset using yarn changeset then we can merge and cut a release?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Please check if the changeset makes sense 👍

@NullScope NullScope marked this pull request as ready for review August 26, 2022 15:22
@ardatan ardatan merged commit 4e4fac0 into ardatan:master Aug 26, 2022
@ardatan
Copy link
Owner

ardatan commented Aug 26, 2022

Thanks @NullScope :)

@NullScope
Copy link
Contributor Author

Thanks @NullScope :)

No problem! Thanks for the speedy review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants